{% extends "layout.html" %}
{% block body %}

<h2>我的博客</h2>
<!--table-bordered-->
<table class="table table-striped table-hover">
    <thead>
      <tr>
        <th width="50%">标题</th>
        <th width="30%">上传时间</th>
        <th width="20%">操作</th>
      </tr>
    </thead>
    <tbody>
     {% for item in list %}
        <tr>
            <td>{{item.name}}</td>
            <td>{{item.post_time}}</td>
            <td>
                <button type="button" onclick="javascript:window.location.href='{{url_for('article.edit',id=item.id)}}'" class="btn btn-link">编辑</button>
                <button type="button" onclick="btnDel({{item.id}})" class="btn btn-link">删除</button>
            </td>
        </tr>
    {% endfor %}
    </tbody>
</table>

<script>
    function btnDel(id){
        if(confirm("确认删除？")){
            var paramData={
                id:id
            }
            $.ajax({
                type:'POST',
                url:'{{url_for("article.delete")}}',
                data:paramData,
                dataType:'json',
                success:function(data){
                    if(data.code=="succ"){
                        alert("操作成功");
                        window.location.reload();
                    }
                    else if(data.code=="login_timeout"){
                        alert(data.msg);
                        window.location.href="/account/login";
                    }
                    else{
                        alert(data.msg);
                    }
                }
            });
        }
    }
</script>
{% endblock %}
